package com.loongtech.bi.manager.pay;

import com.loongtech.bi.entity.pay.EntityNewUserAddCashUser;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NewUserAddCashUserManager extends ManagerQueryCacheBase<EntityNewUserAddCashUser> {
	private static final long serialVersionUID = 1L;

    public List<EntityNewUserAddCashUser> getNewUserAddCashUsersByDate(Date dateStart, Date dateEnd) {
        return findByQuery("from EntityNewUserAddCashUser where 1=1 and day>=:dayStart and day<=:dayEnd order by day ", "dayStart", dateStart, "dayEnd", dateEnd);
    }

    public List<EntityNewUserAddCashUser> getNewUserAddCashUsersByDate2(Date dateStart, Date dateEnd) {
        return findByQuery("from EntityNewUserAddCashUser where 1=1 and day>=:dayStart and day<=:dayEnd and serverid='0' order by day ", "dayStart", dateStart, "dayEnd", dateEnd);
    }

    /**
     * 开服至今付费付费人数
     * @param dateStart
     * @param dateEnd
     * @return
     */
    public Long getNewUserAddCashUsersFromOpenDate(Date dateStart, Date dateEnd) {
        Long ss = getByQuery("select sum(new_user_addcash_user) from EntityNewUserAddCashUser where 1=1 and day>=:dayStart and day<=:dayEnd and platformid = '0' and channelid = '0' and serverid = '0'", "dayStart", dateStart, "dayEnd", dateEnd);
        return ss == null ? 0 : ss;
    }

    public List<Object[]> getNewUserAddCashUsersFromOpenDate2(Date dateStart, Date dateEnd) {
        return findByQuery("select platformid, sum(new_user_addcash_user) from EntityNewUserAddCashUser where 1=1 and day>=:dayStart and day<=:dayEnd and channelid = '0' and serverid = '0' group by platformid ", "dayStart", dateStart, "dayEnd", dateEnd);
    }

    /**
     * 开服至今付费人数（分平台）
     * @param dateStart
     * @param dateEnd
     * @return
     */
    public Long getNewUserAddCashUsersFromOpenDateByPlatform(Date dateStart, Date dateEnd, String platformid) {
        Long ss = getByQuery("select sum(new_user_addcash_user) from EntityNewUserAddCashUser where 1=1 and day>=:dayStart and day<=:dayEnd and platformid =:platformid ", "dayStart", dateStart, "dayEnd", dateEnd, "platformid",platformid);
        return ss == null ? 0 : ss;
    }
}
